import qrcode from "qrcode-terminal";
import { WechatyBuilder, ScanStatus } from "wechaty";
export const wechaty = WechatyBuilder.build();
wechaty.botInfo = null;
const onLogout = (user) => {
  console.log(`用户 ${user} 退出成功`);
  wechaty.botInfo = null;
};
const onLogin = (user) => {
  console.log(`用户 ${user} 登录成功`);
  wechaty.botInfo = user;
};
const onError = console.error;
const onScan = (code, status) => {
  // status: 2代表等待，3代表扫码完成
  status === ScanStatus.Waiting &&
    qrcode.generate(code, { small: true }, console.log);
};

wechaty
  .on("scan", onScan)
  .on("login", onLogin)
  .on("logout", onLogout)
  .on("error", onError)
